import 'package:get/get.dart';
import 'package:largefriends/config/lf_route.dart';
import 'package:largefriends/entity/entities/lf_bool_entity.dart';
import 'package:largefriends/net/error_handle.dart';
import 'package:largefriends/net/lf_api_url.dart';
import 'package:largefriends/net/lf_dio_util.dart';
import 'package:largefriends/service/lf_auth_service.dart';
import 'package:largefriends/utils/lf_dialog_utils.dart';

toSetting() {
  Get.toNamed(LFRoute.pathSetting);
}

class LfSettingLogic extends GetxController {
  LfAuthService authService = Get.find();
  RxInt messageStatus = 1.obs;
  RxString version = '1.0.0'.obs;

  changeMessageStatus(int status) {
    showLoading();
    LfDio().post<LfBoolEntity>(
      url: apiSetNotification,
      params: {'type': 'message', 'status': status},
    ).then((value) {
      hideLoading();
      messageStatus.value = status;
    }, onError: (error) {
      hideLoading();
      if (error is NetError) {
        showSnackBar(error.msg);
      }
    });
  }

  @override
  void onInit() {
    super.onInit();
    messageStatus.value = authService.messageNotificationStatus;
  }
}
